package com.elinshaw.singleton;

/**
 * 单例
 *
 * @author Administrator
 */
public final class Singleton {

    private Singleton() {
    }

    private static volatile Singleton singleton = null;

    /**
     * 双重检查方式
     *
     * @return
     */


    public static Singleton getInstance1() {
        if (singleton == null) {
            synchronized (Singleton.class) {
                if (singleton == null) {
                    singleton = new Singleton();
                }
            }
        }
        return singleton;
    }

    /**
     * holder方式
     */
    private static class Holder {
        private static Singleton instance = new Singleton();
    }

    public static Singleton getInstance2() {
        return Holder.instance;
    }

}
